import { handleAction, refreshTable } from ".";
import { merchantList } from "./store";
import { handleSearchLoading } from "@userList/search";
const searchLoading = ref(false);
const resetLoading = ref(false);
export const addLoading = ref(false);
export const searchConfig = () => {
  const defineSearch = {
    okText: getProxyT("base.query"),
    cancelText: getProxyT("base.reset"),
    searchLoading,
    resetLoading,
    refreshTableData: async (searchParams: any, type: any) => {
      searchParams.status =
        searchParams.status + "" === "Infinity"
          ? undefined
          : searchParams.status;
      handleSearchLoading(true, type, defineSearch);
      await refreshTable(searchParams);
      handleSearchLoading(false, type, defineSearch);
    },
    extra: () => (
      <>
        {withDirectivePower({
          vNode: (
            <s-button
              type="primary -> create"
              loading={addLoading.value}
              onClick={() => handleAction({ type: "add" })}
            >
              {$t("base.addChannel")}
            </s-button>
          ),
          bindingValue: "channelApi.add",
        })}
      </>
    ),
    searchList: [
      {
        label: getProxyT("table14"),
        type: "select",
        model: "merchant_uid",
        placeholder: getProxyT("placeholder24"),
        searchClass: "search-item-width-150",
        allowClear: true,
        options: merchantList,
      },
      {
        label: getProxyT("table65"),
        type: "input",
        model: "username",
        allowClear: true,
        placeholder: getProxyT("placeholder25"),
      },
      {
        label: getProxyT("table66"),
        type: "input",
        model: "name",
        allowClear: true,
        placeholder: getProxyT("placeholder20"),
      },
      {
        label: getProxyT("table79"),
        type: "select",
        model: "status",
        placeholder: getProxyT("placeholder26"),
        searchClass: "search-item-width-150",
        allowClear: true,
        options: [
          {
            label: getProxyT("dict6"),
            value: "",
          },
          {
            label: getProxyT("dict7"),
            value: 0,
          },
          {
            label: getProxyT("dict8"),
            value: 1,
          },
        ],
      },
      {
        label: getProxyT("table44"),
        type: "rangePicker",
        model: "start_end",
        placeholder: computed(() => [$t("base.startTime"), $t("base.endTime")]),
      },
    ],
  };
  return defineSearch;
};
